#
# Licensed to Selene developers ('Selene') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# Selene licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

Import('venv')

from os.path import dirname

sources = Split("""
core/arrays.c
core/certs.c
core/certs_asn1_time.c
core/client.c
core/conf.c
core/conf_certs.c
core/error.c
core/event.c
core/init.c
core/log.c
core/mem.c
crypto/digest_osx_commoncrypto.c
crypto/digest_openssl.c
crypto/encrypt_openssl.c
crypto/encrypt_osx_commoncrypto.c
crypto/hmac.c
crypto/hmac_osx_commoncrypto.c
crypto/hmac_openssl.c
crypto/prf.c
crypto/rsa_openssl.c
io/brigades.c
io/buckets.c
io/io.c
io/tok.c
parser/alert_io.c
parser/alert_messages.c
parser/common.c
parser/handshake_io.c
parser/handshake_callbacks.c
parser/handshake_messages.c
parser/handshake_messages/certificate.c
parser/handshake_messages/client_hello.c
parser/handshake_messages/client_key_exchange.c
parser/handshake_messages/change_cipher_spec.c
parser/handshake_messages/finished.c
parser/handshake_messages/server_hello.c
parser/handshake_messages/server_hello_done.c
parser/parser.c
parser/parser_init.c
parser/state_machine.c
parser/tls_io.c
parser/tls_messages.c
""")

libselene = None

lenv = venv.Clone()
caheader = lenv.CertificateHeader(lenv.File('selene_trusted_ca_certificates.h'), lenv.Glob("#/misc/ca-tools/*.crt"))
lenv.AppendUnique(CPPPATH=['#/include/private', dirname(caheader[0].get_abspath())])
# TODO: find better way to deal with generated header / make generated .c ?
# sources.append(caheader)

if lenv['SELENE_LIB_TYPE'] == "STATIC":
  libselene = lenv.StaticLibrary('libselene', sources)
elif venv['SELENE_LIB_TYPE'] == "SHARED":
  libselene = lenv.SharedLibrary('libselene', sources)

Return('libselene')
